<?php

namespace App\Backend\Controllers;

use App\Backend\Controllers\BaseController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

use App\Backend\Service\DoubanPushService;

/**
 * 豆瓣
 */
class DoubanPushController extends BaseController
{
    private $getRules=[
            'img_url'=> 'required',
            'type'=> 'required',
            'sort'=> 'required',
            'status'=> 'required',
    ];
    private $getRulesMessage=[
            'img_url.required'=> '图片地址不能为空',
            'type.required'=> 'banner类型不能为空',
            'sort.required'=> '排序不能为空',
            'status.required'=> '状态不能为空',
    ];
    
    public function __construct(DoubanPushService $centerService)
    {
        $this->repository = $centerService;
        parent::__construct();
    }

    /**
     * 添加
     */
    public function add(Request $request)
    {
        $group_name=$request->json('group_name');
        $group_type='买组';
        if($group_name=='买组'){
            $group_type=3;
        }
        if($group_name=='拼租'){
            $group_type=4;
        }


        $data = [
            'user_id'=>0,
            'cover'=>'',//默认取第一张图片
            'content_books'=>[],
            'title'=>$request->json('title'),
            'nickname'=>$request->json('userName'),
            'unique_id'=>$request->json('id'),
            'publish_time'=>$request->json('publicTime'),
            'avatar'=>$request->json('avatar'),
            'group_type'=>$group_type,
            'contents'=>$request->json('contents'),
            'article_url'=>$request->json("url"),
            'images'=>[],
            'channel'=>'豆瓣',
            'like_count'=>'0',
            'collect_count'=>'0',
            'comment_count'=>'0',
            'view_count'=>'0',
            'status'=>'1',
            'is_delete'=>'2', //是否删除 1  删除  2 不删除
        ];



        if(empty($data['content_books'])){
            $data['content_books']=[];
        }
        if(empty($data['images'])){
            $data['images']=[];
        }
        //die("sdfsd");

        
        $this->repository->add($request,$data);
        $alert='success';
        echo json_encode($alert);
        exit;
        
    }   


    
}
